package com.cg.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName IdUtils
 * @Description 雪花算法生成雪花id
 * @Author CG
 * @Date 2024/1/3 13:06
 **/
@Component
public class IdUtils {

    //数据中心Id
    @Value("${dataCenterId}")
    private Long dataCenterId;

    //机器编号
    @Value("${workId}")
    private Long workId;

    /**
     * 生成雪花ID
     * @return
     */
    public String getCarNum(){
        Snowflake snowflake = IdUtil.getSnowflake(workId,dataCenterId);
        long num = snowflake.nextId();
        String value = String.valueOf(num);
        return value;
    }
}
